<?php $this->load->view('header');?>

<body class="childrenBody">
    <blockquote class="layui-elem-quote news_search">
		<form class="layui-form" action="" style="display: inline;">
			<div class="layui-inline">
			    <div class="layui-input-inline">
			    	<input type="text" name="keyword" id="keyword" value="" placeholder="订单号/流水号/课程名/会员名" class="layui-input search_input" style="width:250px;">
			    </div>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" id="date" placeholder="时间范围" style="width:250px;">
				</div>
			    <a class="layui-btn layui-btn-normal Sear_btn"><i class="layui-icon">&#xe615;</i>查询</a>
			</div>
		</form>
		<div style="float: right;">
			<div class="layui-inline">
				<!--a class="layui-btn layui-btn-custom userAdd_btn"><i class="layui-icon">&#xe654;</i> </a-->
			</div>
		</div>
		
	</blockquote>

	<!-- 视图 -->
	<div class="layui-form news_list">
		<form class="layui-form">
			<table class="layui-table" lay-even="" lay-skin="line">
			    <thead>
				<tr>					
					<th>课程名称</th>
					<th>卡名称</th>					
					<th>会员名称</th>
					<!--th>订单号</th>
					<th>流水号</th-->
					<th>购买时间</th>
					<th>操作</th>
				</tr> 
			    </thead>
				<tbody class="goods_content" id="view"></tbody>
				
			</table>
			<div class="page_box" style="float: right;padding-right: 10px;">
				<div id="listpage"></div>
			</div>
		</form>
	</div>

	<!-- 模板 -->
	<script id="demo" type="text/html">
	    {{#  layui.each(d.list, function(index, item){ }}
			<tr>			 
			  <td align="left">{{ item.course_name }}</td>
			  <td>{{ item.card_name }}</td>			 
			  <td>{{ item.user_name }}</td>
			   <!--td>{{ item.order_sn }}</td>
			  <td>{{ item.transaction_id }}</td-->
			  <td>{{ item.addtime }}</td>
			  <td>
			  	
			    <a class="layui-btn layui-btn-warm layui-btn-mini" id="edit{{ item.id }}" title="编辑">
			      <i class="layui-icon">&#xe642;</i>查看
			    </a>
			    <!--a class="layui-btn layui-btn-danger layui-btn-mini" id="delete{{ item.id }}" title="删除">
			      <i class="layui-icon">&#xe640;</i>删除
			    </a-->
			  </td>
			</tr>
	    {{#  }); }}

	    {{#  if(d.list.length === 0){ }}
	      暂无数据
	    {{#  } }} 
	</script>

	<script type="text/javascript">
	layui.config({
		version: true
	}).use(['jquery','layer', 'laytpl', 'form', 'element', 'laypage', 'laydate'],function(){
		var layer = parent.layer === undefined ? layui.layer : parent.layer,
			laytpl = layui.laytpl,
			form = layui.form,
			element = layui.element,
			laypage = layui.laypage,
			$ = layui.jquery;
			var laydate = layui.laydate;
			
			//日期范围
			laydate.render({
				elem: '#date',
				range: true
			});
			
			load_list();

			//查询
			$('.Sear_btn').click(function() {			
				var date = $("#date").val();				
				var keyword = $("#keyword").val();	
				load_list('',date,keyword);
			});

			
			function load_list(p,d,k)
			{
				var p = p ? p : '';
				var d = d ? d : '';
				var k = k ? k : '';
			
				$.get('admin.php/Order/get_list',{page:p,date:d,keyword:k}, function(data) 
				{
					var getTpl = demo.innerHTML;
					laytpl(getTpl).render(data, function(html){
					  $('#view').html(html);
					});


					layui.each(data.list, function(index, el) 
					{
						//分页
						laypage.render({
						  elem: 'listpage'
						  ,count: data.count //数据总数，从服务端得到
						  ,theme: '#1E9FFF'
						  ,limit: 10
						  ,curr:p
						  ,jump: function(obj, first){
						    //首次不执行
						    if(!first){
						      load_list(obj.curr,d,k);
						    }
						  }
						});

						//编辑
						$('#edit'+el.id).click(function() 
						{
							var index = layui.layer.open({
								title : "详细",
								type : 2,
								content : "admin.php/Order/get_info/"+el.id,
								cancel: function(index, layero){ 
									location.reload();						 
								}  
							})

							//改变窗口大小时，重置弹窗的高度，防止超出可视区域
							$(window).resize(function(){
								layui.layer.full(index);
							})
							layui.layer.full(index);
						});

						//删除
						$('#delete'+el.id).click(function() 
						{
							layer.confirm('确定删除选中的信息？',{icon:3, title:'提示信息'},function(index){
								$.get('admin.php/Order/del',{id:el.id}, function(res) {
									if (res.status == 200) {
										layer.msg(res.message, {icon:1});
										location.reload();
									}
									else
									{
										layer.msg(res.message, {icon:2});
									}
								},"json");
							});
						});

						form.render(); //更新全部
					});
				},'json');

			}

	});
	</script>

</body>
</html>